package com.wc.AlgoOJ_homework.AlgoOJ_test3.G_晨星;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 20:38
 * @description http://43.138.190.70:8888/p/987?tid=65e5dab127489dab814f76e2
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static long[][] f = new long[N][3];
    static int[][] a = new int[N][2];
    // 离散化
    static int[] c = new int[N << 1];
    static int[] cntX = new int[N << 1];
    static int[] cntY = new int[N << 1];
    static int lenC = 0;
    static int t, n;

    public static void main(String[] args) {
        t = sc.nextInt();
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= Math.min(i, 2); j++) {
                if (j == 0) f[i][j] = 1;
                else f[i][j] += f[i - 1][j - 1] + f[i - 1][j];
            }
        }
        while (t-- > 0) {
            lenC = 0;
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                a[i][0] = sc.nextInt();
                a[i][1] = sc.nextInt();
                c[++lenC] = a[i][0];
                c[++lenC] = a[i][1];
            }
            Arrays.sort(c, 1, lenC + 1);
            c[0] = Integer.MIN_VALUE;
            int j = 0;
            for (int i = 1; i <= lenC; i++) {
                if (c[i] != c[i - 1]) c[++j] = c[i];
            }
            lenC = j;
            Map<Integer, Integer> b1s = new HashMap<>();
            Map<Integer, Integer> b2s = new HashMap<>();
            for (int i = 1; i <= n; i++) {
                cntX[find(a[i][0])]++;
                cntY[find(a[i][1])]++;
            }
            for (int i = 1; i <= n; i++) {
                int b1 = a[i][0] + a[i][1];
                int b2 = a[i][1] - a[i][0];
                b1s.put(b1, b1s.getOrDefault(b1, 0) + 1);
                b2s.put(b2, b2s.getOrDefault(b2, 0) + 1);
            }
            long res = 0;
            for (int i = 1; i <= lenC; i++) {
                res += f[cntX[i]][2];
                res += f[cntY[i]][2];
                cntX[i] = 0;
                cntY[i] = 0;
            }
            for (int val : b1s.values()) {
                res += f[val][2];
            }
            for (int val : b2s.values()) {
                res += f[val][2];
            }
            out.println(res * 2);
        }
        out.flush();
    }

    static int find(int x) {
        int l = 1, r = lenC;
        while (l < r) {
            int mid = l + r >> 1;
            if (c[mid] >= x) r = mid;
            else l = mid + 1;
        }
        return l;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
